package at.fhj.itm11.forum.gui;

import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import at.fhj.itm11.forum.api.ApiLookupNames;
import at.fhj.itm11.forum.gui.pages.ShowPostPage;
import at.fhj.itm11.forum.service.TestHelperService;

public class US10 extends AbstractGUITest {

	private TestHelperService dbHelper;

	@Before
	public void additionalSetUp() {
		dbHelper = lookupBean(ApiLookupNames.TEST_HELPER,
				TestHelperService.class);

		dbHelper.cleanDB();
		dbHelper.createDemoData();
	}

	@Test
	public void testCommentPost() {
		login();
		ShowPostPage showPostPage = navigateToShowPostPage(1);
		showPostPage.commentLink.click();
		showPostPage.commentField.sendKeys("test comment");
		showPostPage.commentButton.click();

		new WebDriverWait(driver, 5)
				.until(ExpectedConditions.textToBePresentInElement(
						By.xpath("//body//div[contains(@id,'content')]//table//tr[contains(@id,'postTable:0:commentList:1')]//td"),
						"test comment"));

		WebElement commentText = driver
				.findElement(By
						.xpath("//body//div[contains(@id,'content')]//table//tr[contains(@id,'postTable:0:commentList:1')]//td"));
		assertTrue(commentText.getText().contains("test comment"));
	}
}
